
* Tables 37-40 
qui{
clear
use "${data}/MEPS_merged_Health_Whites.dta"
keep if AGE1<65 & AGE1>24
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.


gen ESHI=0 if INSCOV_Y1==2 | INSCOV_Y1==3 
replace ESHI=1 if INSCOV_Y1==1 & EMP_Y1!=0 
drop if EMP_Y1==.
drop if PUB1==1 | PUB2==1 | PUB3==1 
drop if H1==.


* keep only uninsured

keep if ESHI==0	 // keeping those completely uninsured
drop if Charges_plus_RX==. 
drop if TOTSLF_Y1==.

keep if I_any_shock==1

* we assume you pay if you have OOP higher or equal to 75% of .6xCharges
gen I_pay=0 if TOTSLF_Y1<.6*.75*Charges_plus_RX 
replace I_pay=1 if TOTSLF_Y1>=.6*.75*Charges_plus_RX 

* generate treatment equal to 1 if charges are higher than $500/year (note the variable is in thousands)
gen I_treat=0 if Charges_plus_RX<.5
replace I_treat=1 if Charges_plus_RX>=.5 

egen mean_OOP= total(TOTSLF_Y1) if Charges_plus_RX>=.5 
egen mean_MC= total(Charges_plus_RX*.6) if Charges_plus_RX>=.5
gen ratio=mean_OOP/mean_MC
tab ratio
	
* TABLE WITH 3 THINGS, LIMITING TO THE COMPLETELY UNINSURED WITH REPORTED SHOCK
* 1. % WITH MC<$500
* 2. % WITH OOP<.6*MC IF MC>500
* 3. mean(OOP)/mean(MC) IF MC>500 	

replace I_pay=. if Charges_plus_RX<0.500 // I_pay is conditional on treatment

label var ratio "OOP/(Charges*0.6) if treat"
label var I_treat "% treat"
label var I_pay "% pay if treat"

** Table 37 in appendix
gen All=1
table  (All) ,  statistic(mean I_treat) statistic(mean I_pay) statistic(mean ratio)  nototals nformat(%5.2f)  
collect title "MEPS Data"
collect export "${out_tables}/MC_stats.tex", tableonly replace


drop ratio
bysort H1: egen total_OOP= total(TOTSLF_Y1) if Charges_plus_RX>=.5
bysort H1: egen total_MC= total(Charges_plus_RX*.6) if Charges_plus_RX>=.5
 gen ratio=total_OOP/total_MC
 label var ratio "OOP/(Charges*0.6) if treat"

 * Table 38 in Appendix
table  (H1) ,  statistic(mean I_treat) statistic(mean I_pay) statistic(mean ratio)  nototals nformat(%5.2f)  
collect title "MEPS Data"
collect export "${out_tables}/MC_stats_H.tex", tableonly replace

* Table 39 in Appendix
table  (age_group2) if age_group2<65 ,  statistic(mean I_treat) statistic(mean I_pay) nototals nformat(%5.2f)  
collect title "MEPS Data"
collect export "${out_tables}/MC_stats_age.tex", tableonly replace

* Table 40 in Appendix 
table  (age_group2) H1 if age_group2<65 ,  statistic(mean I_treat)  nototals nformat(%5.2f)  
collect title "MEPS Data"
collect export "${out_tables}/MC_stats_age_H.tex", tableonly replace
}


* Save data to compare with model data - Figures 10 and 11
* MEDICAL CHARGES - INSURED VS UNINSURED.
qui{
clear
use "${data}/MEPS_merged_Health_Whites.dta"
keep if AGE1<65
drop if AGE1==24
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.

gen I_suspicious1 = 1 if Charges_plus_RX<Expenditures_incl_RX & Expenditures_incl_RX!=. & Charges_plus_RX!=.
replace I_suspicious1 = 0 if Charges_plus_RX>=Expenditures_incl_RX & Expenditures_incl_RX!=. & Charges_plus_RX!=.
tab  I_suspicious1

keep if  I_suspicious1 == 0 & H1!=. & Charges_plus_RX!=. 

gen MCAID_yr1= 0 if MCAID1==0 & MCAID2==0 & MCAID3==0 
replace MCAID_yr1= 1 if MCAID1==1 | MCAID2==1 | MCAID3==1
replace INSCOV_Y1=2 if INSCOV_Y1==1 & MCAID_yr1== 1 // if they had Medicaid anytime during the year, make the replacement.


	
preserve
collapse (mean)	Charges_plus_RX, by(age_group2 educ_group)
rename age_group2 age_group
rename educ_group education
reshape wide Charges_plus_RX, i(age_group) j(education)
drop if age_group==65
replace age_group=age_group+2

save "${data}\Charges Moments 1 data.dta",  replace
restore 

preserve 
collapse (mean)	Charges_plus_RX, by(age_group2 INSCOV_Y1)
rename age_group2 age_group	
reshape wide Charges_plus_RX, i(age_group) j(INSCOV_Y1)
drop if age_group==65
replace age_group=age_group+2
sort  age_group
save "${data}\Charges Moments 2 data.dta",  replace
restore

preserve 
collapse (mean)	Charges_plus_RX, by(age_group2 INSCOV_Y1_alt)
rename age_group2 age_group	
drop if INSCOV_Y1_alt==.
reshape wide Charges_plus_RX, i(age_group) j(INSCOV_Y1_alt)
drop if age_group==65
replace age_group=age_group+2
sort age_group
save "${data}\Charges Moments 3 data.dta",  replace
restore 

preserve
collapse (mean)	Charges_plus_RX, by(age_group2 INSCOV_Y1 educ_group)
rename age_group2 age_group	
rename educ_group education
reshape wide Charges_plus_RX, i(age_group education) j(INSCOV_Y1)
drop if age_group==65
replace age_group=age_group+2
sort age_group education
save "${data}\Charges Moments 4 data.dta",  replace	
restore

collapse (mean)	Charges_plus_RX, by(age_group2)
rename age_group2 age_group	
drop if age_group==65
replace age_group=age_group+2
sort age_group 
save "${data}\Charges Moments 5 data.dta",  replace	
}